package com.chat.business.controller;

import com.chat.business.service.IApplyService;
import com.chat.business.service.IGroupService;
import com.chat.business.service.IMessageChannelMappingService;
import com.chat.common.dto.GetGroupDTO;
import com.chat.common.dto.GroupDTO;
import com.chat.common.dto.ProcessApplyDto;
import com.chat.common.dto.SendGroupApplyDto;
import com.chat.common.entity.Group;
import com.chat.common.form.ListForm;
import com.chat.common.vo.GetGroupVO;
import com.chat.common.vo.GroupVO;
import com.chat.common.vo.R;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息频道/群聊
 *
 * @author wei kunJie
 * @date 2024/3/30 14:09:39
 */
@RestController
@RequestMapping("/business/channel/group")
public class GroupsChannelMappingController {
    @Resource
    private IMessageChannelMappingService messageChannelMappingService;
    @Resource
    private IGroupService groupService;
    @Resource
    private IApplyService applyService;

    /**
     * @ignore
     * 获取用户的群聊
     * @param userId
     * @return
     */
    @GetMapping("/getUserGroups")
    public R<List<GroupVO>> getUserGroups(@RequestParam Long userId){
        return messageChannelMappingService.getUserGroups(userId);
    }

    /**
     * 条件获取全部的群聊
     * @param getGroupDTO
     * @return
     */
    @PostMapping("/getUserGroups")
    public R<ListForm<GetGroupVO>> getAllGroups(@RequestBody GetGroupDTO getGroupDTO){
        return R.succeed(groupService.getAllGroups(getGroupDTO));
    }

    /**
     * 加群申请
     * @return
     */
    @PostMapping("/addGroupApply")
    public R addGroupApply(@RequestBody SendGroupApplyDto sendGroupApplyDto){
        return applyService.sendGroupApply(sendGroupApplyDto);
    }

    /**
     * 处理加群申请
     * @return
     */
    @PostMapping("/processGroupApply")
    public R processGroupApply(@RequestBody ProcessApplyDto processApplyDto){
        return applyService.processGroupApply(processApplyDto);
    }

    /**
     * 创建群聊
     * @param dto
     * @return
     */
    @PostMapping("/createGroup")
    public R<GroupVO> createGroup(@RequestBody GroupDTO dto){
       return groupService.createGroup(dto);
    }

    /**
     * 解散群
     * @param dto
     * @return
     */
    @PostMapping("/disposeGroup")
    public R disposeGroup(@RequestBody GroupDTO dto){
        return groupService.disbandGroup(dto);
    }

    /**
     * 更新群信息
     * @param dto
     * @return
     */
    @PostMapping("/updateGroupData")
    public R updateGroupData(@RequestBody GroupDTO dto){
        return groupService.updateGroupData(dto);
    }

    /**
     * 禁用群
     * @param
     * @return
     */
    @GetMapping("/disableGroup")
    public R DisableGroup(@RequestParam("groupId") @NotBlank(message = "ID不能为空") String ID) {
        return groupService.DisableGroup(ID);
    }

    /**
     * 启用群
     * @param ID
     * @return
     */
    @GetMapping("/enableGroup")
    public R EnableGroup(@RequestParam("groupId") @NotBlank(message = "ID不能为空") String ID) {
        return groupService.EnableGroup(ID);
    }

    /**
     * 根据群号获取群信息
     * @param groupAccount
     * @return
     */
    @GetMapping("/group_account")
    public R<Group> getGroupByAccount(@RequestParam @NotBlank(message = "群号不能为空") String groupAccount) {
        return groupService.getGroupByAccount(groupAccount);
    }
}
